/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.wisnu.scs.view;

import com.wisnu.scs.controller.DbBarangMasukController;
import com.wisnu.scs.dao.DbBarangDao;
import com.wisnu.scs.dao.DbBarangMasukDao;
import com.wisnu.scs.entity.DbBarang;
import com.wisnu.scs.entity.DbBarangMasuk;
import com.wisnu.scs.error.ErrorMessage;
import com.wisnu.scs.event.DbBarangMasukListener;
import com.wisnu.scs.model.DbBarangMasukModel;
import com.wisnu.scs.model.tableModel.DbBarangMasukTableModel;
import com.wisnu.scs.util.HibernateUtil;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JComboBox;
import javax.swing.JFormattedTextField;
import javax.swing.JRadioButton;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

/**
 *
 * @author Wisnu Wardoyo
 */
public class DbBarangMasukView extends javax.swing.JPanel implements DbBarangMasukListener, ListSelectionListener {

    DbBarang dbBarang;
    DbBarangMasuk dbBarangMasuk;
    DbBarangMasukTableModel tableModel;
    DbBarangMasukController controller;
    DbBarangMasukModel model;

    List<DbBarang> listDbBarang;

    public DbBarangMasukView() {
        tableModel = new DbBarangMasukTableModel();

        model = new DbBarangMasukModel();
        model.setListener(this);
        controller = new DbBarangMasukController();
        controller.setModel(model);

        initComponents();

        tableBarangMasuk.getSelectionModel().addListSelectionListener(this);
        tableBarangMasuk.setModel(tableModel);
    }

    public DbBarang getDbBarang() {

        return dbBarang;

    }

    public DbBarangMasuk getDbBarangMasuk() {
        return dbBarangMasuk;
    }

    public JRadioButton getRadioByDate() {
        return radioByDate;
    }

    public JRadioButton getRadioByMonth() {
        return radioByMonth;
    }

    public JRadioButton getRadioByRange() {
        return radioByRange;
    }

    public JTable getTableBarangMasuk() {
        return tableBarangMasuk;
    }

    public JFormattedTextField getTxtFirstDate() {
        return txtFirstDate;
    }

    public JTextField getTxtIdPemasukan() {
        return txtIdPemasukan;
    }

    public JTextField getTxtJumlah() {
        return txtJumlah;
    }

    public JTextPane getTxtKeterangan() {
        return txtKeterangan;
    }

    public JFormattedTextField getTxtLastDate() {
        return txtLastDate;
    }

    public JComboBox getComboName() {
        return comboName;
    }

    public JTextField getTxtSearchText() {
        return txtSearchText;
    }

    public JTextField getTxtSumberDana() {
        return txtSumberDana;
    }

    public JFormattedTextField getTxtTanggalMasuk() {
        return txtTanggalMasuk;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tableBarangMasuk = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        txtSearchText = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        radioByMonth = new javax.swing.JRadioButton();
        radioByRange = new javax.swing.JRadioButton();
        jLabel1 = new javax.swing.JLabel();
        txtFirstDate = new javax.swing.JFormattedTextField();
        jLabel2 = new javax.swing.JLabel();
        txtLastDate = new javax.swing.JFormattedTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        txtTanggalMasuk = new javax.swing.JFormattedTextField();
        txtSumberDana = new javax.swing.JTextField();
        txtJumlah = new javax.swing.JTextField();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtKeterangan = new javax.swing.JTextPane();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        txtIdPemasukan = new javax.swing.JTextField();
        comboName = new javax.swing.JComboBox();
        radioByDate = new javax.swing.JRadioButton();
        jLabel9 = new javax.swing.JLabel();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();

        setBackground(new java.awt.Color(255,255,255,20)
        );
        setMinimumSize(new java.awt.Dimension(666, 376));

        jPanel1.setBackground(new java.awt.Color(255,255,255,20)
        );
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Tabel Barang Masuk"));

        tableBarangMasuk.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(tableBarangMasuk);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 588, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1)
                .addContainerGap())
        );

        jPanel2.setBackground(new java.awt.Color(255,255,255,20)
        );
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Administrator Panel"));

        jButton1.setText("Search");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        radioByMonth.setText("`By Month");
        radioByMonth.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radioByMonthActionPerformed(evt);
            }
        });

        radioByRange.setText("`By Date's Range");
        radioByRange.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radioByRangeActionPerformed(evt);
            }
        });

        jLabel1.setText("From :");

        txtFirstDate.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(java.text.DateFormat.getDateInstance(java.text.DateFormat.LONG))));
        txtFirstDate.setEnabled(false);
        txtFirstDate.setValue(new java.util.Date());

        jLabel2.setText("To :");

        txtLastDate.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(java.text.DateFormat.getDateInstance(java.text.DateFormat.LONG))));
        txtLastDate.setEnabled(false);
        txtLastDate.setValue(new java.util.Date());
        txtLastDate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtLastDateActionPerformed(evt);
            }
        });

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel3.setText("Nama Barang :");

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel4.setText("Tanggal Masuk :");

        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel5.setText("Sumber Dana :");

        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel6.setText("Jumlah :");

        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel7.setText("Keterangan :");

        txtTanggalMasuk.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(java.text.DateFormat.getDateInstance(java.text.DateFormat.LONG))));
        txtTanggalMasuk.setValue(new java.util.Date());

        jScrollPane2.setViewportView(txtKeterangan);

        jButton2.setText("Tambah");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("Ubah");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("Hapus");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setText("Reset");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel8.setText("Id Pemasukan :");

        txtIdPemasukan.setEditable(false);

        comboName.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Pilih Jenis Barang" }));
        comboName.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboNameActionPerformed(evt);
            }
        });

        radioByDate.setText("`By Date");
        radioByDate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radioByDateActionPerformed(evt);
            }
        });

        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel9.setText("Search");

        jButton6.setText("Show All");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jButton7.setText("Print");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jLabel7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING))
                                .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(18, 18, 18)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(txtJumlah, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(txtSumberDana, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(txtTanggalMasuk, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jScrollPane2)
                                .addComponent(txtIdPemasukan, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(comboName, javax.swing.GroupLayout.Alignment.LEADING, 0, 183, Short.MAX_VALUE))))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 114, Short.MAX_VALUE)
                            .addComponent(radioByDate, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtFirstDate, javax.swing.GroupLayout.Alignment.LEADING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtLastDate, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(radioByRange)))
                    .addComponent(jLabel9)
                    .addComponent(txtSearchText, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(radioByMonth, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel9)
                .addGap(3, 3, 3)
                .addComponent(txtSearchText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1))
                .addGap(1, 1, 1)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtFirstDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtLastDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(radioByDate)
                    .addComponent(radioByRange))
                .addGap(3, 3, 3)
                .addComponent(radioByMonth)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton6)
                    .addComponent(jButton7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(txtIdPemasukan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(comboName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtTanggalMasuk, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtSumberDana, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(txtJumlah, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 88, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jButton3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton4)
                    .addComponent(jButton5))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void comboNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboNameActionPerformed
        if (comboName.getItemCount() != 0 && comboName.getSelectedIndex() != 0) {
            String[] array = comboName.getSelectedItem().toString().split("-");
            for (DbBarang barang : listDbBarang) {
                if (barang.getIdBarang() == Integer.parseInt(array[0])) {
                    dbBarang = barang;
                    break;
                }
            }
        }
    }//GEN-LAST:event_comboNameActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        controller.insertPemasukan(this);
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        controller.updatePemasukan(this);
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        controller.resetForm();
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        controller.deletePemasukan(this);
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        controller.searchPemasukan(this);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        try {
            loadTable();
            loadDatabase();
        } catch (ErrorMessage ex) {

        }
    }//GEN-LAST:event_jButton6ActionPerformed

    private void radioByDateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioByDateActionPerformed
        if (radioByDate.isSelected()) {
            radioByDate.setSelected(true);
            radioByMonth.setSelected(false);
            radioByRange.setSelected(false);

            txtFirstDate.setEnabled(true);
            txtLastDate.setEnabled(false);
        } else {
            radioByDate.setSelected(false);
            radioByMonth.setSelected(false);
            radioByRange.setSelected(false);

            txtFirstDate.setEnabled(false);
            txtLastDate.setEnabled(false);
        }
    }//GEN-LAST:event_radioByDateActionPerformed

    private void radioByMonthActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioByMonthActionPerformed
        if (radioByMonth.isSelected()) {
            radioByDate.setSelected(false);
            radioByMonth.setSelected(true);
            radioByRange.setSelected(false);

            txtFirstDate.setEnabled(true);
            txtLastDate.setEnabled(false);
        } else {
            radioByDate.setSelected(false);
            radioByMonth.setSelected(false);
            radioByRange.setSelected(false);

            txtFirstDate.setEnabled(false);
            txtLastDate.setEnabled(false);
        }
    }//GEN-LAST:event_radioByMonthActionPerformed

    private void radioByRangeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioByRangeActionPerformed
        if (radioByRange.isSelected()) {
            radioByDate.setSelected(false);
            radioByMonth.setSelected(false);
            radioByRange.setSelected(true);

            txtFirstDate.setEnabled(true);
            txtLastDate.setEnabled(true);
        } else {
            radioByDate.setSelected(false);
            radioByMonth.setSelected(false);
            radioByRange.setSelected(false);

            txtFirstDate.setEnabled(false);
            txtLastDate.setEnabled(false);
        }
    }//GEN-LAST:event_radioByRangeActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        controller.print(this);
    }//GEN-LAST:event_jButton7ActionPerformed

    private void txtLastDateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtLastDateActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtLastDateActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox comboName;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JRadioButton radioByDate;
    private javax.swing.JRadioButton radioByMonth;
    private javax.swing.JRadioButton radioByRange;
    private javax.swing.JTable tableBarangMasuk;
    private javax.swing.JFormattedTextField txtFirstDate;
    private javax.swing.JTextField txtIdPemasukan;
    private javax.swing.JTextField txtJumlah;
    private javax.swing.JTextPane txtKeterangan;
    private javax.swing.JFormattedTextField txtLastDate;
    private javax.swing.JTextField txtSearchText;
    private javax.swing.JTextField txtSumberDana;
    private javax.swing.JFormattedTextField txtTanggalMasuk;
    // End of variables declaration//GEN-END:variables

    public void loadDatabase() throws ErrorMessage {
        DbBarangDao barangDao = HibernateUtil.getBarangDao();

        this.listDbBarang = barangDao.selectAllBarang();
        comboName.removeAllItems();
        comboName.addItem("Pilih Nama Barang");
        for (DbBarang barang : listDbBarang) {
            comboName.addItem(barang.getIdBarang() + "-" + barang.getNamaBarang());
        }
        try {
            dbBarang = listDbBarang.get(0);
        } catch (IndexOutOfBoundsException exception) {
        }
        repaint();
    }

    public void loadTable() throws ErrorMessage {
        DbBarangMasukDao barangMasukDao = HibernateUtil.getBarangMasukDao();
        tableModel = new DbBarangMasukTableModel();
        tableModel.setList(barangMasukDao.selectAllBarangMasuk());
        tableBarangMasuk.setModel(tableModel);
        repaint();
    }

    @Override
    public void onReset(DbBarangMasukModel model) {
        txtIdPemasukan.setText(model.getIdPemasukan() + "");
        comboName.setSelectedIndex(0);
        txtJumlah.setText(model.getJumlah() + "");
        txtSumberDana.setText(model.getSumberDana());
        txtKeterangan.setText(model.getKeterangan());

        txtSearchText.setText(model.getSearchText());
        txtFirstDate.setValue(model.getFirstDate());
        txtLastDate.setValue(model.getLastDate());

    }

    @Override
    public void onInsert(DbBarangMasuk barangMasuk) {
        tableModel.add(barangMasuk);
    }

    @Override
    public void onDelete(DbBarangMasuk barangMasuk) {
        int index = tableBarangMasuk.getSelectedRow();
        tableModel.remove(index);
    }

    @Override
    public void onUpdate(DbBarangMasuk barangMasuk) {
        int index = tableBarangMasuk.getSelectedRow();
        tableModel.set(index, barangMasuk);
    }

    @Override
    public void onSearch(List<DbBarangMasuk> barangMasuk) {
        tableModel = new DbBarangMasukTableModel();
        tableModel.setList(barangMasuk);
        tableBarangMasuk.setModel(tableModel);
        repaint();
    }

    @Override
    public void valueChanged(ListSelectionEvent lse) {
        try {
            this.dbBarangMasuk = tableModel.get(tableBarangMasuk.getSelectedRow());
            txtIdPemasukan.setText(dbBarangMasuk.getIdMasuk() + "");
            txtTanggalMasuk.setValue(dbBarangMasuk.getTanggalMasuk());
            txtSumberDana.setText(dbBarangMasuk.getSumberDana());
            txtJumlah.setText(dbBarangMasuk.getJumlah() + "");
            txtKeterangan.setText(dbBarangMasuk.getKeterangan());

            dbBarang = dbBarangMasuk.getDbBarang();

            comboName.setSelectedItem(dbBarang.getIdBarang() + "-" + dbBarang.getNamaBarang());

        } catch (IndexOutOfBoundsException exception) {

        }
    }

}
